let tabLI = document.querySelectorAll(".content .tab-div li")
let tabDIV = document.querySelectorAll(".content .tab-con>div")
for (let i = 0; i < tabLI.length; i++) {
    tabLI[i].onclick = () => {
        for (let j = 0; j < tabLI.length; j++) {
            tabLI[j].classList.remove("active");
            tabDIV[j].classList.add("none");
        }
        tabLI[i].classList.add("active");
        tabDIV[i].classList.remove("none");
    }
}

//验证码登录
let phoneInput = document.querySelectorAll(".content .tab-con .phone-login li input");
let phoneclear = document.querySelectorAll(".content .tab-con .phone-login li .clearbtn");
for (let i = 0; i < phoneInput.length; i++) {
    phoneInput[i].oninput = () => {
        if (phoneInput[i].value != '') {
            phoneInput[i].nextElementSibling.classList.remove("none");
        }
    }
}
for (let i = 0; i < phoneclear.length; i++) {
    phoneclear[i].onclick = () => {
        phoneclear[i].previousElementSibling.value = '';
        phoneclear[i].classList.add("none");
    }
}



//账号登录
let normalInput = document.querySelectorAll(".content .tab-con .normal-login li input");
let normalclear = document.querySelectorAll(".content .tab-con .normal-login li .clearbtn");
let show = document.querySelector(".content .tab-con .normal-login li .show");
for (let i = 0; i < normalInput.length; i++) {
    normalInput[i].oninput = () => {
        if (normalInput[i].value != '') {
            normalInput[i].nextElementSibling.classList.remove("none");
        }
    }
}
for (let i = 0; i < normalclear.length; i++) {
    normalclear[i].onclick = () => {
        normalclear[i].previousElementSibling.value = '';
        normalclear[i].classList.add("none");
    }
}
//眼睛显示
// show.onclick = () => {
//     show.classList.toggle("hid_pasw");
//     if (show.previousElementSibling.previousElementSibling.type == "password") {
//         show.previousElementSibling.previousElementSibling.type = "text";
//     } else {
//         show.previousElementSibling.previousElementSibling.type = "password";
//     }
// }

//手机号验证
let reg = /^[1-9]\d{10}$/
let phoneNum = document.querySelector("#phoneNum")
let phonePwd = document.querySelector("#phonePwd")
let loginName = document.querySelector("#loginName")
let loginPwd = document.querySelector("#loginPwd")
let submit = document.querySelector(".phone-login .submit")
let submit1 = document.querySelector(".normal-login .submit")

if (localStorage.getItem('userPhone')) {
    let userName = localStorage.getItem('userPhone')
    let password = '111111'
    loginName.value = userName
    loginPwd.value = password
}

submit.onclick = () => {
    if (reg.test(phoneNum.value)) {
        // console.log(111);
        axios.post("http://localhost:3001/login_phone", {
            phone: phoneNum.value
        }).then(res => {
            console.log(res);
            phonePwd.value = res.data.num
            if (res.data.status == 1) {
                location.href = `City-Travel-mine.html?phone=${phoneNum.value}?status=${res.data.status}`
            }
        }).catch(err => {
            console.log(err);
        })
    } else {
        mark.classList.remove("none")
        setInterval(() => {
            mark.classList.add("none")
        }, 1000)
    }
}
submit1.onclick = () => {
    if (reg.test(loginName.value)) {
        // console.log(111);
        axios.post("http://localhost:3001/login_pwd", {
            phone: loginName.value,
            pwd: loginPwd.value
        }).then(res => {
            console.log(res);
            if (res.data.status == 1) {
                location.href = `City-Travel-mine.html?phone=${loginName.value}?status=${res.data.status}`
            }
        }).catch(err => {
            console.log(err);
        })
    } else {
        mark.classList.remove("none")
        setInterval(() => {
            mark.classList.add("none")
        }, 1000)
    }
}